function [c,ceq] = nonl_6c_p(x)
%load remaining data
data_struct = load('data6c.mat');
Y = data_struct.Y;
eps = data_struct.eps;
bound = data_struct.bound;
upMat = data_struct.upMat;
os = double(data_struct.os);
uniqSeg = double(data_struct.uniqSeg);
prices = double(data_struct.prices);
capcon = double(data_struct.capcon);
segScale = double(data_struct.segScale);
segQ = double(data_struct.segQ);
rem_cap = double(data_struct.rem_cap);
uniqSeg_size = size(uniqSeg);
nNewSegments = uniqSeg_size(1);
prices_size = size(prices);
nProducts = prices_size(1);
[y1,y2,y3]=ind2sub(size(upMat),find(upMat));
nRes = length(rem_cap);

prices_lb = zeros(nProducts,nProducts,nNewSegments);
for i=1:nNewSegments
     prices_lb(y1(i),y2(i),i) = prices(y1(i));
end

u = zeros(nNewSegments,3+nProducts);
usub = zeros(nNewSegments,nProducts);
for i = 1:nNewSegments
    u(i,:) = [uniqSeg(i,1)+1,y1(i),y2(i),os(uniqSeg(i,3)+1,:)];
    usub(i,:) = os(uniqSeg(i,3)+1,:);
    usub(i,y2(i)) = 0;
end

%Matrix A
anzNBcap = find(rem_cap~=0,1,'last')-1;
anzNByp = nNewSegments;
anzEV = 2*nNewSegments;
A = zeros(anzNBcap+anzNByp,anzEV);
for i = 1:anzNBcap
    h = i+1; 
    for n = 1:nNewSegments
        A(i,n) = capcon(y1(n),i)-capcon(y1(n),h);
    end
end
A(anzNBcap+1:anzNBcap+anzNByp,1:nNewSegments) = diag(ones(nNewSegments,1));
A(anzNBcap+1:anzNBcap+anzNByp,nNewSegments+1:2*nNewSegments) = -diag(Y(sub2ind(size(Y),y1,y2,y3)));

%b, Aeq, beq
b = [rem_cap(2:anzNBcap+1)';zeros(anzNByp,1)];

c = A*x-b;
ceq = [];

end